﻿<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/Site.Master" CodeBehind="AuthorEditTest.aspx.cs" Inherits="JustTest.Author.AuthorEditTest" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">    
             <asp:FormView runat="server"
             ID="TestEditFormView"
             DataKeyNames="Id"
             OnItemCommand="TestEditFormView_ItemCommand"
             SelectMethod="TestEditFormView_GetItem"
             UpdateMethod="TestEditFormView_UpdateItem"
             ItemType="JustTest.Models.Test"
             DefaultMode="Edit">
            <EditItemTemplate>
                <table>
                    <tr>
                        <td>Category: </td>
                         <td><asp:DropDownList runat="server"
                             ID="CategoryDropDown"
                             SelectMethod="CategoryDropDown_SelectItem"
                             ItemType="JustTest.Models.Category"
                             DataTextField="Name"
                             DataValueField="Id"
                             SelectedValue="<%# BindItem.CategoryId %>">
                            </asp:DropDownList></td>
                    </tr>
                    <tr>
                        <td>Title: </td>
                        <td>
                            <asp:TextBox ID="TitleInput" runat="server" Text="<%# BindItem.Title %>" />
                            <asp:RequiredFieldValidator Display="None" runat="server" ValidationGroup="TestValidation" ErrorMessage="Title Is Required !" ControlToValidate="TitleInput" >
                            </asp:RequiredFieldValidator>
                            <asp:RegularExpressionValidator ControlToValidate="TitleInput"  Display="None" ValidationGroup="TestValidation"
                            ValidationExpression="[A-Za-z0-9?.!-,:; ]{6,}" ErrorMessage="Title Has To Be With Min Length 6 And Only valid Letters And Numbers !" runat="server">
                            </asp:RegularExpressionValidator>
                        </td>
                    </tr>
                    <tr>
                        <td>Description: </td>
                        <td>
                            <asp:TextBox ID="DescriptionInput" TextMode="MultiLine" style="resize:none" runat="server" Text="<%# BindItem.Description %>" />
                            <asp:RequiredFieldValidator ControlToValidate="DescriptionInput" ValidationGroup="TestValidation" Display="None" 
                                ErrorMessage="Description Is Required" runat="server"></asp:RequiredFieldValidator>
                        </td>

                    </tr>
                    <tr>
                        <td colspan="2">
                          <asp:ListView runat="server"
                              DefaultMode="Insert"
                              ID="QuestionListView"
                              DataKeyNames="Id"
                              InsertItemPosition="FirstItem"
                              OnItemInserted="QuestionListView_ItemInserted"
                              SelectMethod="QuestionListView_GetData"
                              ItemPlaceholderID="QuestionsPlaceholder"
                              ItemType="JustTest.Models.Question"
                              OnDataBound="QuestionListView_DataBound"
                              UpdateMethod="QuestionListView_UpdateItem"
                              DeleteMethod="QuestionListView_DeleteItem"
                              InsertMethod="QuestionCreateFormView_InsertItem">
                              <LayoutTemplate>
                                  <h3>Questions : </h3>
                                      <asp:LinkButton ClientIDMode="Static" ID="QuestionLayoutCreateButton" Visible="false"
                                          Text="Create New Question ..." runat="server" OnClick="QuestionLayoutCreateButton_Click">
                                      </asp:LinkButton>
                                  <hr />
                                   <asp:DataPager ID="QuestionsDataPager" ClientIDMode="static" runat="server" PageSize="1" PagedControlID="QuestionListView">
                                    <Fields>
                                        <asp:NextPreviousPagerField  ShowFirstPageButton="false"  PreviousPageText="Prev Question"
                                             ShowNextPageButton="false" ShowPreviousPageButton="true" />
                                         <asp:NumericPagerField />
                                        <asp:NextPreviousPagerField ShowLastPageButton="false" 
                                            NextPageText="Next Question"
                                            ShowNextPageButton="true" ShowPreviousPageButton="false" />
                                    </Fields>
                                  </asp:DataPager>
                                  <div id="QuestionsPlaceholder" runat="server">
                                  </div>
                                 <hr />
                              </LayoutTemplate>
                              <EditItemTemplate>
                                   <div>
                                        <label>Edit Your Question: </label>
                                        <asp:TextBox runat="server" ID="QuestionContentInputEdit" ClientIDMode="Static" Text="<%# BindItem.Content %>"></asp:TextBox> 
                                        <asp:Button runat="server" Text="Update" CommandName="Update" ValidationGroup="QuestionEdit" CssClass="btn btn-info" />
                                        <asp:Button runat="server" Text="Cancel" CommandName="Cancel" CssClass="btn btn-info" />       
                                        <br />
                                        <asp:RequiredFieldValidator ForeColor="red" ValidationGroup="QuestionEdit" Display="Dynamic" runat="server" ErrorMessage="</br>Content Is Required !" ControlToValidate="QuestionContentInputEdit" ></asp:RequiredFieldValidator>
                                  </div>
                              </EditItemTemplate>
                              <InsertItemTemplate>
                                    <div>
                                        
                                        <label for="QuestionContentInput">New Question : </label>
                                        <asp:TextBox runat="server" ID="QuestionContentInput" ClientIDMode="Static" Text="<%# BindItem.Content %>"></asp:TextBox>
                                        <asp:Button runat="server" Text="Create Question" CommandName="Insert" ValidationGroup="QuestionInsert" />
                                        <asp:Button runat="server" Text="Cancel" CommandName="Cancel" CssClass="btn btn-info" OnClick="Unnamed_Click" /> 
                                        <br />
                                        <asp:RequiredFieldValidator ForeColor="red" ValidationGroup="QuestionInsert" Display="Dynamic" runat="server" ErrorMessage="</br>Content Is Required !" ControlToValidate="QuestionContentInput" ></asp:RequiredFieldValidator>
                                    </div>
                                  <hr />
                              </InsertItemTemplate>
                              <ItemTemplate>
                                      <div>
                                            <div id="questionContentBox"><asp:DynamicControl DataField="Content" Mode="ReadOnly" runat="server" /></div>
                                            <asp:Button runat="server" Text="Edit" CommandName="Edit" CausesValidation="false" />
                                            <asp:Button runat="server" Text="Delete" CommandName="Delete" CausesValidation="false" />                                          
                                      </div>
                                      
                                      <asp:ListView runat="server"
                                          ID="AnswersListView"
                                          ItemPlaceholderID="AnswerPlaceholder"
                                          ItemType="JustTest.Models.Answer"
                                          DataKeyNames="Id"
                                          InsertItemPosition="LastItem"
                                          SelectMethod="AnswersListView_GetData"
                                          InsertMethod="AnswersListView_InsertItem"
                                          DeleteMethod="AnswersListView_DeleteItem"
                                          UpdateMethod="AnswersListView_UpdateItem">
                                          <LayoutTemplate>
                                              <hr />
                                              <h4>Answers</h4>
                                              <table id="AnswersListView">
                                                  <thead>
                                                      <th>Content</th>
                                                      <th>Value</th>
                                                      <th>Actions</th>
                                                  </thead>
                                                  <tbody id="AnswerPlaceholder" runat="server">

                                                  </tbody>
                                              </table>
                                          </LayoutTemplate>
                                          <ItemTemplate>
                                              <tr>
                                                  <td><asp:DynamicControl runat="server" DataField="Content" Mode="ReadOnly" /></td>
                                                  <td><asp:DynamicControl runat="server" DataField="Value" Mode="ReadOnly" /></td>
                                                  <td>
                                                      <asp:Button runat="server" Text="Edit" CommandName="Edit" CausesValidation="false" CssClass="btn btn-info" />
                                                      <asp:Button runat="server" Text="Delete" CommandName="Delete" CausesValidation="false" CssClass="btn btn-info" />
                                                  </td>
                                              </tr>
                                          </ItemTemplate>
                                          <EditItemTemplate>
                                               <tr>
                                                  <td>
                                                      <asp:TextBox runat="server" ID="AnswerContentInputEdit" Text="<%#BindItem.Content %>"></asp:TextBox>
                                                      <br />
                                                      <asp:RequiredFieldValidator ValidationGroup="AnswerValidationEdit" Display="Dynamic" runat="server" ErrorMessage="Content Is Required !" ControlToValidate="AnswerContentInputEdit" ></asp:RequiredFieldValidator>
                                                      <asp:RegularExpressionValidator ValidationGroup="AnswerValidationEdit"  Display="Dynamic"  ControlToValidate="AnswerContentInputEdit" 
                                                          ValidationExpression=".{1,}" ErrorMessage="Content Should Be With Min Length 6" runat="server"></asp:RegularExpressionValidator>
                                                  </td>
                                                  <td>
                                                      <asp:TextBox runat="server" ID="AnswerValueInputEdit" ClientIDMode="Static" Text="<%#BindItem.Value %>"></asp:TextBox>
                                                      <br />
                                                      <asp:RequiredFieldValidator ValidationGroup="AnswerValidationEdit" Display="Dynamic"  runat="server" ErrorMessage="Value Is Required !" ControlToValidate="AnswerValueInputEdit" ></asp:RequiredFieldValidator>
                                                      <asp:RegularExpressionValidator ValidationGroup="AnswerValidationEdit"  Display="Dynamic"  ControlToValidate="AnswerValueInputEdit" 
                                                          ValidationExpression="\d{1,}" ErrorMessage="Value Should Be valid Integer !" runat="server"></asp:RegularExpressionValidator>
                                                  </td>
                                                  <td>
                                                      <asp:Button runat="server" Text="Update" CommandName="Update" ValidationGroup="AnswerValidationEdit" />
                                                      <asp:Button runat="server" Text="Cancel" CommandName="Cancel" />
                                                  </td>
                                              </tr>
                                          </EditItemTemplate>
                                          <InsertItemTemplate>
                                              <tr>
                                                  <td>
                                                      <asp:TextBox runat="server" ID="AnswerContentInput" Text="<%# BindItem.Content %>"></asp:TextBox>
                                                      <asp:RequiredFieldValidator ValidationGroup="AnswerValidation" Display="None" runat="server" ErrorMessage="Content Is Required !" ControlToValidate="AnswerContentInput" ></asp:RequiredFieldValidator>
                                                      <asp:RegularExpressionValidator ValidationGroup="AnswerValidation"  Display="None"  ControlToValidate="AnswerContentInput" 
                                                          ValidationExpression=".{1,}" ErrorMessage="Content Should Be With Min Length 6" runat="server"></asp:RegularExpressionValidator>
                                                  </td>
                                                  <td>
                                                      <asp:TextBox runat="server" ID="AnswerValueInput" ClientIDMode="Static" Text="<%# BindItem.Value %>"></asp:TextBox>
                                                      <asp:RequiredFieldValidator ValidationGroup="AnswerValidation" Display="None"  runat="server" ErrorMessage="Value Is Required !" ControlToValidate="AnswerValueInput" ></asp:RequiredFieldValidator>
                                                      <asp:RegularExpressionValidator ValidationGroup="AnswerValidation"  Display="None"  ControlToValidate="AnswerValueInput" 
                                                          ValidationExpression="\d{1,}" ErrorMessage="Value Should Be valid Integer !" runat="server"></asp:RegularExpressionValidator>
                                                  </td>
                                                  <td>
                                                      <asp:Button runat="server" Text="Insert" CommandName="Insert" ValidationGroup="AnswerValidation" />
                                                  </td>
                                              </tr>
                                              <tr>
                                                  <td colspan="3">
                                                       <asp:ValidationSummary ValidationGroup="AnswerValidation" runat="server" ShowSummary="true" DisplayMode="BulletList" Style="color: Red" />
                                                  </td>
                                              </tr>
                                          </InsertItemTemplate>
                                      </asp:ListView>
                              </ItemTemplate>
                          </asp:ListView>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3">
                            <asp:Button runat="server" ValidationGroup="TestValidation" CommandName="Update" Text="Update Test" CssClass="btn btn-info" />
                            <asp:Button runat="server" ValidationGroup="TestValidation"  CommandName="Update" CommandArgument="released" Text="Release" CssClass="btn btn-info" />
                            <asp:Button runat="server" Text="Cancel" OnClick="Unnamed_Click1" CssClass="btn btn-info"/>

                        </td>
                        </td>
                    </tr>
                </table>
            </EditItemTemplate>
        </asp:FormView>
       <asp:ValidationSummary ID="StudentsValidationSummary" ValidationGroup="TestValidation"
                     runat="server" ShowSummary="true" DisplayMode="BulletList" Style="color: Red" />
</asp:Content>